package com.niit.agricstore.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.niit.agricstore.entity.Product;
import com.niit.agricstore.entity.Type;
import com.niit.agricstore.entity.vo.ProductVo;
import com.niit.agricstore.mapper.GoodsMapper;
import com.niit.agricstore.service.GoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

////商品管理
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper,Type> implements GoodsService {
    @Autowired
    GoodsMapper goodsMapper;


    /**商品分类**/
    //基本信息
    @Override
    public PageInfo<Product> selectProductAndPictureByPageAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Product> list = goodsMapper.selectProductAndPictureByPageAll();
        PageInfo pageInfo = new PageInfo<>(list);
        System.out.println("分页信息"+pageInfo);
        return pageInfo;
    }
    //根据商品分类查询
    @Override
    public PageInfo<Product> selectProductAndPictureByType(Integer type_id, Integer pageNum, Integer pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Product> list = goodsMapper.selectProductAndPictureByType(type_id);
        PageInfo pageInfo = new PageInfo<>(list);
        System.out.println("分页信息"+pageInfo);
        return pageInfo;
    }
    //根据商品分类id查询


    //添加产品分类
    @Override
    public int insert(Type type) {return goodsMapper.insert(type);}
    //编辑产品分类
    @Override
    public int updateTypeById(Type type) {return goodsMapper.updateTypeById(type);}

    //删除分类
    @Override
    public int deleteTypeById(Integer typeId) {return goodsMapper.deleteTypeById(typeId);}


    /**单品管理**/
    //创建
    @Override
    public int addGoods(Product product) {return goodsMapper.addGoods(product);}


    //信息编辑
    @Override
    public int updateGoods(Product product) {
        return goodsMapper.updateGoods(product);
    }
    //上架和下架货品
    @Override
    public int deleteGoodsId(Integer productId) {
        return goodsMapper.deleteGoodsId(productId);
    }

    @Override
    public Product selectGoodsById(Integer productId) {
        return goodsMapper.selectGoodsById(productId);
    }
    //根据id查询


    @Override
    public ProductVo selectProductAndPictureById(Integer productId) {
        return goodsMapper.selectProductAndPictureById(productId);
    }

    @Override
    public int delByGoodId(int productId) {
        return  goodsMapper.delByGoodId(productId);
    }

    @Override
    public int updateByProductId(int productId, int productSale, int productTotal, float productNowPrice) {
        return 0;
    }




    @Override
    public void updateById(Product product) {
        goodsMapper.updateById(product);
    }




}
